#include "head.h"

// 初始化那个父进程用来监听的socket
int initSocket(int* socket_fd, char* ip, char* port){

    *socket_fd = socket(AF_INET, SOCK_STREAM, 0);
    ERROR_CHECK(*socket_fd, -1, "socket");
    
    
    int reuse = 1;
    setsockopt(*socket_fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));

    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(atoi(port));
    addr.sin_addr.s_addr = inet_addr(ip);
    
    bind(*socket_fd, (struct sockaddr* )&addr, sizeof(addr));

    listen(*socket_fd, 10);

    return 0;
}
